package chenji.gunapi.bullet.accuracy;

import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

import chenji.gunapi.GunAPI;
import chenji.gunapi.listeners.PlayerStateListener.PlayerState;

public class Accuracy {
	AccurafyEntry accx;
	AccurafyEntry accy;
	AccurafyEntry accz;
	Player p;

	public Accuracy(AccurafyEntry accx, AccurafyEntry accy, AccurafyEntry accz, Player p) {
		this.accx = accx;
		this.accy = accy;
		this.accz = accz;
	}

	public Vector getFinal() {
		PlayerState ps = GunAPI.getGunAPI().getPlayerState().getState(p);
		return new Vector(accx.getFinalValue(ps), accy.getFinalValue(ps), accz.getFinalValue(ps));
	}
}

class AccurafyEntry {
	private double def;
	private double walking;
	private double random;
	private double siting;
	private double walkandsiting;

	public AccurafyEntry(double def, double walking, double random, double siting, double walkandsiting) {
		this.def = def;
		this.walkandsiting = walkandsiting;
		this.random = random;
		this.siting = siting;
		this.walking = walking;
	}

	public double getFinalValue(PlayerState state) {

		double start = 0;

		switch (state) {
		case STATIC:
			start = this.def;
		case SITING:
			start = this.siting;
		case WALKING:
			start = this.walking;
		case WALKINGANDSITING:
			start = this.walkandsiting;
		}
		return start + this.random * Math.random();
	}
}
